﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinFu.IoC.Interfaces;
using LinFu.IoC.Configuration;

namespace CoreEx.MicroMapper.Implementation
{
    [Factory(typeof(ITableMapper<>))]
    public class TableMapperFactory : IFactory
    {
        public object CreateInstance(IFactoryRequest request)
        {
            Type mapperType = typeof(TableMapper<>);
            Type genericMapperType = mapperType.MakeGenericType(request.ServiceType.GetGenericArguments());
            object instance = Activator.CreateInstance(genericMapperType);
            ((IInitialize)instance).Initialize(request.Container);
            return instance; 
        }
    }
}
